﻿using Glue.Internals;
using Xunit;

namespace GlueTests
{
    namespace NullableTypeComparerTest
    {
        public class When_comparing_with_nullable_types
        {
            private readonly NullableTypeComparer comparer;

            public When_comparing_with_nullable_types()
            {
                comparer = new NullableTypeComparer();
            }

            [Fact]
            public void Should_return_true_when_one_type_is_the_nullable_version_of_the_other()
            {
                
                Assert.True(comparer.AreOneTheNullableVersionOfTheOther(typeof(int?), typeof(int)));
            }

            [Fact]
            public void Should_return_false_when_both_types_are_the_same_nullable_types()
            {
                Assert.False(comparer.AreOneTheNullableVersionOfTheOther(typeof(int?), typeof(int?)));
            }

            [Fact]
            public void Should_return_false_if_nullable_type_is_of_different_type()
            {
                Assert.False(comparer.AreOneTheNullableVersionOfTheOther(typeof(bool?),typeof(int)));
            }

            [Fact]
            public void Should_return_false_if_different_nullable_types()
            {
                Assert.False(comparer.AreOneTheNullableVersionOfTheOther(typeof(bool?), typeof(int?)));
            }

            [Fact]
            public void Should_return_false_if_no_type_is_nullable()
            {
                Assert.False(comparer.AreOneTheNullableVersionOfTheOther(typeof(int), typeof(int)));
            }
        }

        public class When_checking_if_equal
        {
            private readonly NullableTypeComparer comparer;

            public When_checking_if_equal()
            {
                comparer = new NullableTypeComparer();
            }


            [Fact]
            public void Should_return_true_when_one_type_is_the_nullable_version_of_the_other()
            {

                Assert.True(comparer.AreEqualOrNullableEqual(typeof(int?), typeof(int)));
            }

            [Fact]
            public void Should_return_true_when_both_types_are_the_same_nullable_types()
            {
                Assert.True(comparer.AreEqualOrNullableEqual(typeof(int?), typeof(int?)));
            }

            [Fact]
            public void Should_return_true_if_no_type_is_nullable()
            {
                Assert.True(comparer.AreEqualOrNullableEqual(typeof(int), typeof(int)));
            }

            [Fact]
            public void Should_return_false_if_nullable_type_is_of_different_type()
            {
                Assert.False(comparer.AreEqualOrNullableEqual(typeof(bool?), typeof(int)));
            }

            [Fact]
            public void Should_return_false_if_different_nullable_types()
            {
                Assert.False(comparer.AreEqualOrNullableEqual(typeof(bool?), typeof(int?)));
            }


        }
        
    }
}
